Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: More Macintosh Toolbox

Previous | Chapter Top | Chapter Contents | Next |

Accessing a Component's Resource File

If you store your component in a component resource and register your component using the RegisterComponentResource function or RegisterComponentResourceFile function, or if the Component Manager automatically registers your component, the Component Manager allows your component to gain access to its resource file. You can store read-only data for your component in its resource file. For example, the resource file may contain the color icon for the component, static data needed to initialize private storage, or any other data that may be useful to the component. Note that there is only one resource file associated with a component.

If you store your component in a component resource but register the component with the RegisterComponent function, rather than with the RegisterComponentResource or RegisterComponentResourceFile function, your component cannot access its resource file with the routines described in this section.

The routines described in this section allow your component to gain access to its resource file. These routines provide read-only access to the data in the resource file. If your component opens its resource file, it must close the file before returning to the calling application.

Use the OpenComponentResFile function to open your component's resource file. Use the CloseComponentResFile function to close the resource file before returning to the calling application.

OpenComponentResFile

The OpenComponentResFile function allows your component to gain access to its resource file. This function opens the resource file with read permission and returns a reference number that your component can use to read data from the file. The Component Manager adds the resource file to the current resource chain. Your component must close the resource file with the CloseComponentResFile function before returning to the calling application.

Your component can use FSpOpenResFile or equivalent Resource Manager routines to open other resource files, but you must use OpenComponentResFile to open your component's resource file.

FUNCTION OpenComponentResFile (aComponent: Component): Integer;
aComponent
A component identifier that specifies the component whose resource file you wish to open. Applications that register components may obtain this identifier from the RegisterComponentResource function.

DESCRIPTION

The OpenComponentResFile function returns a reference number for the appropriate resource file. This function returns 0 or a negative number if the specified component does not have an associated resource file or if the Component Manager cannot open the resource file.

Note that when working with resources, your component should always first save the current resource file, perform any resource operations, then restore the current resource file to its previous value before returning.

CloseComponentResFile

This function closes the resource file that your component opened previously with the OpenComponentResFile function.

FUNCTION CloseComponentResFile (refnum: Integer): OSErr;
refnum
The reference number that identifies the resource file to be closed. Your component obtains this value from the OpenComponentResFile function.

DESCRIPTION

The CloseComponentResFile function closes the specified resource file. Your component must close any open resource files before returning to the calling application.

RESULT CODES

noErr

0

No error

resFNotFound

-193

Resource file not found


© 1999 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next